/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package net.risesoft.risebi.collection.web.admin;

import java.util.Date;
import java.util.Map;

import net.risesoft.risebi.collection.model.SystemLog;
import net.risesoft.risebi.collection.model.User;
import net.risesoft.risebi.collection.service.SystemLogManager;
import net.risesoft.risebi.collection.web.BaseAction;
import net.risesoft.risebi.commons.struts2extension.Trimable;
import net.risesoft.risebi.commons.util.JSONUtil;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionInvocation;

/**
 *
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
public class SystemLogAction extends BaseAction implements Trimable {

	private static final long serialVersionUID = -5085259838522014671L;
	
	private SystemLogManager systemLogManager;
	
	public void setSystemLogManager(SystemLogManager systemLogManager) {
		this.systemLogManager = systemLogManager;
	}
	
	private SystemLog systemLog;
	
	private Date startDate;
	
	private Date endDate;
	
	private String sort;

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public SystemLog getSystemLog() {
		return systemLog;
	}

	public void setSystemLog(SystemLog systemLog) {
		this.systemLog = systemLog;
	}

	@Action(value="list",
			results={@Result(name="success", location="/admin/systemlog/list.jsp")}
	)
	public String list() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="refreshJson")
	public String refreshJson() throws Exception {
		User user = this.getSessionUser();
		
		if(systemLog==null)
			systemLog = new SystemLog();
		
		Map map = null;
		if("system".equalsIgnoreCase(this.whichJson)){
			map = (Map)systemLogManager.getPagedSystemLog(systemLog,user, start, limit,startDate,endDate,sort,SystemLog.SYSTEM);
		}else if("service".equalsIgnoreCase(this.whichJson)){
			map = (Map)systemLogManager.getPagedSystemLog(systemLog,user, start, limit,startDate,endDate,sort,SystemLog.SERVICE);
		}else if("user".equalsIgnoreCase(this.whichJson)){
			map = (Map)systemLogManager.getPagedSystemLog(systemLog,user, start, limit,startDate,endDate,sort,SystemLog.USER);
		}
		
		
		this.json = JSONUtil.getJsonString("exclude","actionComment,serviceGuid,userGuid,userType",map);
		return AJAX;
	}

	/* (non-Javadoc)
	 * @see net.risesoft.risebi.commons.struts2extension.Trimable#afterTrim(com.opensymphony.xwork2.ActionInvocation)
	 */
	public void afterTrim(ActionInvocation invocation) {
		
	}

	/* (non-Javadoc)
	 * @see net.risesoft.risebi.commons.struts2extension.Trimable#preTrim(com.opensymphony.xwork2.ActionInvocation)
	 */
	public boolean preTrim(ActionInvocation invocation) {
		return true;
	}
}
